package cn.iocoder.yudao.hires.controller.admin;

import cn.iocoder.yudao.hires.vo.ResumeTagsRespVO;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;


import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;

import  cn.iocoder.yudao.hires.vo.*;
import cn.iocoder.yudao.hires.entity.ResumeTagsDO;
import cn.iocoder.yudao.hires.service.ResumeTagsService;

@Tag(name = "管理后台 - 简历--职业优势")
@RestController
@RequestMapping("/resume/tags")
@Validated
public class ResumeTagsController {

    @Resource
    private ResumeTagsService tagsService;

    @PostMapping("/create")
    @Operation(summary = "创建简历--职业优势")
    //@PreAuthorize("@ss.hasPermission('resume:tags:create')")
    public CommonResult<Integer> createTags(@Valid @RequestBody ResumeTagsSaveReqVO createReqVO) {
        return success(tagsService.createTags(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新简历--职业优势")
    //@PreAuthorize("@ss.hasPermission('resume:tags:update')")
    public CommonResult<Boolean> updateTags(@Valid @RequestBody ResumeTagsSaveReqVO updateReqVO) {
        tagsService.updateTags(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除简历--职业优势")
    @Parameter(name = "id", description = "编号", required = true)
    //@PreAuthorize("@ss.hasPermission('resume:tags:delete')")
    public CommonResult<Boolean> deleteTags(@RequestParam("id") Integer id) {
        tagsService.deleteTags(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得简历--职业优势")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    //@PreAuthorize("@ss.hasPermission('resume:tags:query')")
    public CommonResult<ResumeTagsRespVO> getTags(@RequestParam("id") Integer id) {
        ResumeTagsDO tags = tagsService.getTags(id);
        return success(BeanUtils.toBean(tags, ResumeTagsRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得简历--职业优势分页")
    //@PreAuthorize("@ss.hasPermission('resume:tags:query')")
    public CommonResult<PageResult<ResumeTagsRespVO>> getTagsPage(@Valid ResumeTagsPageReqVO pageReqVO) {
        PageResult<ResumeTagsDO> pageResult = tagsService.getTagsPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, ResumeTagsRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出简历--职业优势 Excel")
    //@PreAuthorize("@ss.hasPermission('resume:tags:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportTagsExcel(@Valid ResumeTagsPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<ResumeTagsDO> list = tagsService.getTagsPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "简历--职业优势.xls", "数据", ResumeTagsRespVO.class,
                        BeanUtils.toBean(list, ResumeTagsRespVO.class));
    }

}